package com.bestv.search.spider.douban.service.impl;

import com.bestv.search.spider.douban.dao.DouBanVideoBaseInfoDao;
import com.bestv.search.spider.douban.model.DouBanVideoBaseInfo;
import com.bestv.search.spider.douban.service.DouBanVideoBaseInfoManager;

import java.util.Date;
import java.util.List;

public class DouBanVideoBaseInfoManagerImpl implements DouBanVideoBaseInfoManager {

    private DouBanVideoBaseInfoDao douBanVideoBaseInfoDao;

    @Override
    public List<DouBanVideoBaseInfo> getUnSyncedInfo() {
        return douBanVideoBaseInfoDao.getUnSyncedInfo();
    }

    @Override
    public void saveOrUpdate(List<DouBanVideoBaseInfo> updateList) {
        for (DouBanVideoBaseInfo info : updateList) {
            if (douBanVideoBaseInfoDao.existBaseInfo(info)) {
                if (douBanVideoBaseInfoDao.existDouBanInfo(info)) {
                    douBanVideoBaseInfoDao.updateDouBanVideoInfo(info);
                } else {
                    douBanVideoBaseInfoDao.saveDouBanVideoInfo(info);
                }
            } else {
                douBanVideoBaseInfoDao.save(info);
            }
        }
    }

    @Override
    public void update(DouBanVideoBaseInfo info) {
        douBanVideoBaseInfoDao.update(info);
    }

    @Override
    public List<DouBanVideoBaseInfo> getValidInfoBySyncReviewsTime(Date date) {
        return douBanVideoBaseInfoDao.getValidInfoBySyncReviewsTime(date);
    }

    @Override
    public List<DouBanVideoBaseInfo> getValidInfos() {
        return douBanVideoBaseInfoDao.getValidInfos();
    }

    public DouBanVideoBaseInfoDao getDouBanVideoBaseInfoDao() {
        return douBanVideoBaseInfoDao;
    }

    public void setDouBanVideoBaseInfoDao(DouBanVideoBaseInfoDao douBanVideoBaseInfoDao) {
        this.douBanVideoBaseInfoDao = douBanVideoBaseInfoDao;
    }
}
